import random
import time
# import pyautogui
import ddt
from selenium.webdriver.support.select import Select

from Base.BaseSetings import *
from Base.PublicFunction import readTable
# from WoniuBossPOM.ClassManagement_POM_wxj import Object
from WoniuBossPOM.All_Management_POM import All_Mamagement

@ddt.ddt
class cls_management:
    def __init__(self):
        self.obj=All_Mamagement()
        # self.login('WNCD000','woniu123')


    # def close_browser(self):
    #     self.obj.closeBroswer()

    # def login(self,username,password):
    #     self.obj.username().send_keys(username)
    #     self.obj.password().send_keys(password)
    #     self.obj.veryficode().send_keys('0000')
    #     self.obj.logion_button().click()
    #     time.sleep(2)

    # def close_browser(self):
    #     self.obj.closeBroswer()

    # def login(self,username,password):
    #     self.obj.username().send_keys(username)
    #     self.obj.password().send_keys(password)
    #     self.obj.veryficode().send_keys('0000')
    #     self.obj.logion_button().click()
    #     time.sleep(2)

    # def login_out(self):
    #     time.sleep(2)
    #     self.obj.login_out().click()

    def cls_manage(self,cls_num,direction,teacher):  # 班级管理-学员转班
        self.obj.cls_management().click()            #点击班务管理
        self.obj.cls_manage().click()                #点击班级管理
        time.sleep(2)
        self.obj.add_button().click()                 #点击新增

        self.obj.cls_num().clear()                    #清空班号

        self.obj.cls_num().send_keys(cls_num)         #输入班号
        list=Select(self.obj.direction())             #方向下拉框修改,使其变成可输入文本
        list.select_by_visible_text(direction)
        self.obj.start_cls().click()                  #点击开班时间
        self.obj.start_cls_time().click()             #选择开班时间
        list=Select(self.obj.teacher())               #班主任下拉框修改
        list.select_by_visible_text(teacher)
        self.obj.save_button().click()               #点击保存 (42次操作)

        # self.obj.add_success().click()               #点击确定
        time.sleep(2)
        return self.obj.add_success().text           #返回新增班级成功文本

        # return self.obj.add_success().text           #返回新增班级成功文本
        # self.obj.add_success().click()               #点击确定
        # return self.obj.add().text           #返回新增


    # def readtable(self,tableObj):  # 自定义读表函数
    #     tbodyObj=tableObj.find_element_by_tag_name('tbody')
    #     trObjs=tbodyObj.find_elements_by_tag_name('tr')       #得到所有行
    #     full_list=[]
    #     for trObj in trObjs:                                  #得到每一行
    #         tdObjs=trObj.find_elements_by_tag_name('td')      #从每一行中得到所有列
    #         list=[]
    #         for tdObj in tdObjs:                              #遍历所有行里的每一列
    #             list.append(tdObj.text)                       #获取单元格文本，加第二级列表内
    #         full_list.append(list)                            #在把第二级列表加入大列表内
    #     return full_list                                      #返回二级列表


    def stu_leave(self,leave_day,stu_name,leave_cause):     #学员请假
        self.obj.cls_management().click()            #点击班务管理
        self.obj.stu_leave().click()                 #点击学员请假
        time.sleep(2)
        self.obj.button_add1().click()                #新增按钮
        self.obj.start_time().click()                 #开始时间
        self.obj.select_start_time().click()
        self.obj.end_time().click()                   #结束时间
        self.obj.select_end_time().click()
        time.sleep(2)
        self.obj.keepout_view().click()
        list=Select(self.obj.type_leave())            #选择请假类型
        count=len(list.options)
        index=random.randint(0,count-1)
        list.select_by_index(index)
        self.obj.leave_day().send_keys(leave_day)     #输入请假天数
        time.sleep(2)
        self.obj.stu_name().send_keys(stu_name)       #输入学生姓名
        time.sleep(1)
        self.obj.stu_name_button().click()            ###点击输入姓名后带出来的学号
        # self.obj.switch_to.alert.accept()
        # self.obj.stu_name().send_keys(Keys.ENTER)
        # pyautogui.press('enter')
        list=Select(self.obj.deduct())                #是否扣分
        count = len(list.options)
        index = random.randint(0, count - 1)
        list.select_by_index(index)
        self.obj.keepout_view().click()
        self.obj.leave_cause().send_keys(leave_cause) #输入请假原因
        self.obj.save_button1().click()               #点击保存（保存不成功）



    # @ddt.file_data(TestData_dir+"ClassManagement_wxj.yaml")
    def stu_leave_select(self,region,status_leave,leave_stu_name):   #学员请假信息查询
        self.obj.cls_management().click()                    #点击班务管理
        self.obj.stu_leave().click()                         #点击学员请假
        time.sleep(3)
        time.sleep(3)
        self.obj.stu_leave().click()                         #点击学员请假
        time.sleep(2)

        list=Select(self.obj.region())                       #区域
        list.select_by_visible_text(region)
        time.sleep(2)
        list=Select(self.obj.status_leave())                 #请假状态
        list.select_by_visible_text(status_leave)
        time.sleep(2)
        self.obj.leave_stu_name().send_keys(leave_stu_name)  #输入请假学生姓名
        self.obj.select_button().click()                     #点击查询按钮
        time.sleep(2)
        tableObj=self.obj.stu_leave_table()                  #获取学生请假的表单对象
        return readTable(tableObj)                           # 调用读表函数，得到二维列表

    # @ddt.file_data(TestData_dir + "ClassManagement_wxj.yaml")
    def stu_change(self,school_region,change_cls):           # 学员转班（已实现随机修改）
        self.obj.cls_management().click()                    #点击班务管理

        time.sleep(2)
        self.obj.stu_change().click()                        #点击学员转班
        time.sleep(2)
        self.obj.leave_cls().click()                         #点击转班按钮
        list=Select(self.obj.school_region())                #选择校区
        list.select_by_visible_text(school_region)
        list=Select(self.obj.change_cls())                   #选择班级
        list.select_by_visible_text(change_cls)
        self.obj.accept_button().click()                     #点击确定
        time.sleep(2)
        self.obj.accept().click()                            #点击确定
        time.sleep(2)

        return (self.obj.change_cls_success().text)          #返回转班成功的文本信息

        # self.obj.accept1().click()
        # # return (self.obj.change_cls_success().text)          #返回转班成功的文本信息
        # return (self.obj.souso().text)          #返回转班成功的文本信息


    def stu_change_query(self,school_region,change_cls):              #学员转班信息查询
        self.obj.cls_management().click()                    #点击班务管理
        self.obj.stu_change().click()                        #点击学员转班
        time.sleep(2)
        list=Select(self.obj.region())                       #区域
        list.select_by_visible_text(school_region)
        list=Select(self.obj.cls_room())                     #班级
        list.select_by_visible_text(change_cls)
        self.obj.search_button().click()                     #点击搜索
        tableObj=self.obj.tableObj()                         #或去表单对象
        return readTable(tableObj)




if __name__ == '__main__':
    run=cls_management()
    # run.login('WNCD000','woniu123')
    '''班级管理×'''
    # res=run.cls_manage('1','测试','王飞')
    # print(res)
    '''学员请假×××未写测试用例'''

    # run.stu_leave('2','孙冉','去面试')
    '''学员请假信息查询'''
    res=run.stu_leave_select('成都','请假中','孙冉')
    print(res)

    # run.stu_leave('2','孙冉','去面试')
    '''学员请假信息查询'''
    # res=run.stu_leave_select('成都','请假中','孙冉')
    # print(res)

    '''学员转班'''
    # res=run.stu_change('成都','WNCDC')
    # print(res)
    '''学员转班信息查询'''
    # res=run.stu_change_query('成都','WN00000')
    # print(res)
